home *** CD-ROM | disk | FTP | other *** search
/ MacUser ROM 45 / MACUSER-ROM-VOL-45-1997-08.ISO.7z / MACUSER-ROM-VOL-45-1997-08.ISO / オンラインソフト / オンラインソフト⁄毎号掲載 / インターネット関連 / PageSpinner 2.0 / Examples / JavaScript / Todays Link Example < prev    next >
Text File  |  1996-11-05  |  4KB  |  125 lines

  1. <HTML><HEAD>
  2. <TITLE>JavaScript Today's Link</TITLE>
  3.  
  4. <SCRIPT LANGUAGE="JavaScript">
  5. <!-- Beginning of JavaScript --------
  6. /* 
  7.     Todays Link
  8.     Written by Jerry Aman, Optima System, July 28, 1996.
  9.     Part of the PageSpinner distribution.
  10.  
  11.     We will not be held responsible for any unwanted 
  12.     effects due to the usage of this script or any derivative.  
  13.     No warrantees for usability for any specific application 
  14.     are given or implied.
  15.  
  16.     You are free to use and modify this script,
  17.     if all credits are kept in the source code
  18. */
  19.  
  20.  
  21. function GetTodaysURL()
  22. {
  23.     // Put relative or full URL's in the strings below
  24.     // First line is returned on Mondays, second on Tuesdays ... 
  25.     // ... and the seventh on Sundays
  26.  
  27. var locationlist = new URLList 
  28. (
  29.     "groucho.html",        // Monday
  30.     "harpo.html",        // Tuesday
  31.     "zeppo.html",            
  32.     "chico.html",            
  33.     "harpo.html",            
  34.     "groucho.html",
  35.     "chico.html"        // Sunday
  36. );
  37.  
  38.     now = new Date();
  39.  
  40.     num = now.getDay();
  41.         if (num == 0)
  42.             num = 7;
  43.  
  44.     return locationlist.list[num-1];
  45. }
  46.  
  47. function URLList ()
  48. {
  49.     var argv = URLList.arguments;
  50.     var argc = argv.length;
  51.     this.list = new Object();
  52.     for (var i = 0; i < argc; i++)
  53.     this.list[i] = argv[i];
  54.     this.count = argc;
  55.     return this;
  56. }
  57.  
  58. // -- End of JavaScript code -------------- -->
  59. </SCRIPT>
  60.  
  61. </HEAD>
  62. <BODY BGCOLOR=FFFFFF TEXT=000000>
  63. <H1>JavaScript Today's Link</H1>
  64.  
  65. <B>This page contains a JavaScript that selects a different URL for each day of the
  66. week</B>
  67. <P>
  68. Please note that JavaScript is currently only available in Netscape Navigator 2.0 or higher.<BR>
  69. <FONT COLOR="931B15">Do not assume that all in your audience are using a JavaScript enabled browser.</FONT>
  70. <HR>
  71. <P>
  72. This JavaScript lets you present a different link to a different document URL for each day of the week. 
  73. <P>
  74. You can use this to direct your readers to a different site each day of the week, or if you run a daily newsletter you can use it to let readers to go to a specific file depending on the day of the week.
  75.  
  76. <P>
  77. The script is named <B>GetTodaysURL</B> and it is placed in the HEAD section of the HTML document. The script is executed by clicking on a link containing a call to GetTodaysURL(). Also note the <FONT COLOR="FF3366">custom text</FONT> in Netscape's status area.
  78. <P>
  79.  
  80. Example of this script picking  
  81. <A HREF=""
  82.  onClick="this.href=GetTodaysURL()"
  83.  onMouseOver="window.status='This link takes you the page of the day!'; return true">todays</A> page. Another page will be displayed tomorrow.
  84. <P>
  85.  
  86. <P>
  87. <B><FONT COLOR="DD0000">Internet Explorer Warning!</FONT></B><BR>
  88. Internet Explorer support for JavaScript (called JScript, for obvious reasons ;-) is not as complete as Netscape's implementation, so the script above will give an error message in version 3.0 of MS Internet Explorer for Windows. The 3.0 beta 1 version of Internet Explorer for MacOS doesn't seem to support JScript at all.
  89.  
  90. <P>
  91. View an example of a dynamic script that works around this bug in the <A HREF="Random Link Example">Random Link Example</A>.
  92.  
  93.  
  94. <P>
  95.  
  96. <B>How to use:</B><BR>
  97. Replace the filenames inside the script with your own URLs and edit this page contents inside the <BODY> section. (You can also copy the entire script to one of your existing pages).
  98.  
  99. <XMP>function GetTodaysURL()
  100. {
  101.     // Put relative or full URL's in the strings below
  102.     // First line is returned on Mondays, second on Tuesdays ... 
  103.     // ... and the seventh on Sundays
  104.  
  105. var locationlist = new URLList 
  106. (
  107.     "groucho.html",        // Monday
  108.     "harpo.html",        // Tuesday
  109.     "zeppo.html",            
  110.     "chico.html",            
  111.     "harpo.html",            
  112.     "groucho.html",
  113.     "chico.html"        // Sunday
  114. );
  115. </XMP>
  116. <P>
  117. Use code similar to this to let the user execute the script:
  118. <XMP><A HREF=""
  119.  onClick="this.href=GetTodaysURL()"
  120.  onMouseOver="window.status='Page of the day!';
  121.  return true">Todays page</A></XMP>
  122.  
  123. </BODY>
  124. </HTML>
  125.